﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GPSImei.aspx.cs" Inherits="GPSTrackingWebsiteManager.Pages.GPSImei" %>

<!DOCTYPE html>
<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<link href="../../Css/metro-bootstrap.css" rel="stylesheet" />

<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>
<script src="../../Javascript/ObjectsV2.js"></script>
<script src="../../Javascript/metro.min.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">

            //Windows Message Manager 
            var objWindowsMessageManager = new WindowsMessageManager();

            var opener = GetRadWindow();
            var GPSImei = new GPSImei();

            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow)
                    oWindow = window.radWindow;
                else if (window.frameElement.radWindow)
                    oWindow = window.frameElement.radWindow;
                return oWindow.BrowserWindow;
            }

            function getMenuVehicleTree() {
                return $find('<%= TreeMenuView.ClientID %>');
            }

            function getGroupsTrackDataLastLocationByUser() {
                var tree;
            
                try {
                    tree = getMenuVehicleTree();
                    tree.get_nodes().clear();
                }
                catch (e) {
                    null;
                }

                PageMethods.wsGetGroupsTrackDataLastLocationByUser(getGroupsTrackDataLastLocationByUserOk, getGroupsTrackDataLastLocationByUserError);
            }

            function loadGPSImeiTreeWait() {
                GPSImei.loadGPSImeiTree(getMenuVehicleTree(), opener);
                responseEnd(getrpvGPSImeiUpdateControl());
            }
            
            function getGroupsTrackDataLastLocationByUserOk(xmlObject) {
                requestStart(getrpvGPSImeiUpdateControl());
                GPSImei.openXMLTrackDataLastLocationGroupsImei(xmlObject, opener);
                setTimeout(loadGPSImeiTreeWait, 10);
            }
            
            function getGroupsTrackDataLastLocationByUserError(error) {
                opener.objWindowsMessageManager.show_Error(error.get_message(), titles.polygonoTitle);
            }
            
            function centerImeiTrackDataLastLocationOnClick() {
                GPSImei.showGPSImeiSelected(getMenuVehicleTree(), opener);
            }
            
            function getrpvGPSImeiUpdateControl() {
                return "<%=  RadAjaxPanel1.ClientID %>";
            }
            
            function requestStart(object) {
                try {
                    $find("<%= RadAjaxLoadingPanel1.ClientID%>").show(object);
                }
                catch (e) {
                    null;
                }
            }
            
            function responseEnd(object) {
                //hide the loading panel and clean up the global variables 
                try {
                    $find("<%= RadAjaxLoadingPanel1.ClientID%>").hide(object);
                }
                catch (e) {
                    null;
                }
            }
            
            function SearchBox_OnKeyPress() {
                var txtSearchBox = document.getElementById("txtSearchBox");                
            
                tree = getMenuVehicleTree();
                tree.trackChanges();
                tree.get_nodes().clear();
                tree.commitChanges();
                GPSImei.loadGPSImeiTree(tree, opener, txtSearchBox.value);                          
            }
            
        </script>
    </telerik:RadScriptBlock>
        
    <body onload="getGroupsTrackDataLastLocationByUser()" style="overflow:auto" >
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></telerik:RadScriptManager>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="AjaxControlID1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="Loading" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <div class="metro">
                <div class="input-control text">
                    <input id="txtSearchBox" onkeyup="SearchBox_OnKeyPress()" type="text" placeholder="Buscador ..." autocomplete="off"/>
                    <button class="btn-clear" onclick="SearchBox_OnKeyPress()"></button>
                </div>
            </div>
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">            
                <telerik:RadTreeView ID="TreeMenuView" runat="server" OnClientNodeClicked="centerImeiTrackDataLastLocationOnClick"></telerik:RadTreeView>
            </telerik:RadAjaxPanel>
                
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>

        </form>
    </body>
</html>
    